﻿Public Class ParseCheck
    Public Shared ErrorBrush As Brush = Brushes.Red
    Public Shared ValidBrush As Brush = Brushes.White

    Public Shared Sub IntegerBoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Integer
        If Not Integer.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub

    Public Shared Sub LongBoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Long
        If Not Long.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub

    Public Shared Sub Int16BoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Int16
        If Not Int16.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub

    Public Shared Sub ByteBoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Byte
        If Not Byte.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub

    Public Shared Sub DecimalBoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Decimal
        If Not Decimal.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub

    Public Shared Sub DoubleBoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Double

        If Not Double.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub

    Public Shared Sub SingleBoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Single

        If Not Double.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub

    Public Shared Sub DateBoundsCheck(ByVal sender As Object, ByVal e As EventArgs)
        Dim textbox As TextBox = sender
        If String.IsNullOrEmpty(textbox.Text) Then Exit Sub
        Dim x As Date
        If Not Date.TryParse(textbox.Text, x) Then
            textbox.Background = ErrorBrush
        Else
            textbox.Background = ValidBrush
        End If
    End Sub
End Class
